package main

import "math/rand"

func main() {

}

type Solution struct {
	arr         map[int]int
	total, m, n int
}

func Constructor(m int, n int) Solution {
	return Solution{arr: map[int]int{}, m: m, n: n, total: n * m}
}

func (this *Solution) Flip() (res []int) {
	x := rand.Intn(this.total)
	this.total--
	if v, ok := this.arr[x]; ok {
		res = []int{v / this.n, v % this.n}
	} else {
		res = []int{x / this.n, x % this.n}
	}
	if v, ok := this.arr[this.total]; ok {
		this.arr[x] = v
	} else {
		this.arr[x] = this.total
	}
	return
}

func (this *Solution) Reset() {
	this.arr = map[int]int{}
	this.total = this.m * this.n
}
